import * as _ from "lodash"
import httpClient from "../httpclient"

export class AccessToken {
  private access_token: string
  private token_type: string

  public get accessToken() {
    return this.access_token
  }

  public set accessToken(token: string) {
    this.access_token = token
  }

  public get tokenType() {
    return this.token_type
  }

  public set tokenType(type: string) {
    this.token_type = type
  }
}

export class AccessTokenServiceV1 {
  public static token(username: string, password: string): Promise<AccessToken> {
    return httpClient.post(`/v1/access/token?username=${username}&password=${password}`)
      .then(({ data }) => _.assign(new AccessToken(), data))
      .then(token => {
        return token
      })
  }
}
